﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using DreamIn.Structures;
using DreamIn.Structures.Virtualization;

namespace DreamIn.GUI
{
    /// <summary>
    /// Demo implementation of IItemsProvider returning dummy customer items after
    /// a pause to simulate network/disk latency.
    /// </summary>
    public class CarouselItemProvider : IItemsProvider<CarouselItem>
    {
        private readonly int _count;
        private readonly List<Picture> _pictureList;
        /// <summary>
        /// Initializes a new instance of the <see cref="DemoCustomerProvider"/> class.
        /// </summary>
        /// <param name="count">The count.</param>
        public CarouselItemProvider(int count,List<Picture> pictureList)
        {
            _count = count;
            _pictureList = pictureList;
        }

        /// <summary>
        /// Fetches the total number of items available.
        /// </summary>
        /// <returns></returns>
        public int FetchCount()
        {
            return _count; 
        }

        /// <summary>
        /// Fetches a range of items.
        /// </summary>
        /// <param name="startIndex">The start index.</param>
        /// <param name="count">The number of items to fetch.</param>
        /// <returns></returns>
        public IList<CarouselItem> FetchRange(int startIndex, int count)
        {
            List<CarouselItem> list = new List<CarouselItem>();
            for( int i=startIndex; i<startIndex+count; i++ )
            {
                try
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.UriSource = new Uri(_pictureList[i].PicturePath, UriKind.Absolute);
                    bitmapImage.DecodePixelWidth = 245;
                    bitmapImage.DecodePixelHeight = 180;
                    bitmapImage.EndInit();
                   // CarouselItem carouselItem = new CarouselItem(bitmapImage, _pictureList[i]);
                   // list.Add(carouselItem);
                }
                catch (Exception e)
                {
                }
            }
            return list;
        }
    }
}
